package com.purchase.ml.utils;

/**
 * 正则验证
 * @author kyyang
 *
 */
public class RegexpUtils {
		
	 public static final String rexp1 = "\\s*$|((\\d{2}(([02468][048])|([13579][26]))[\\-]((((0?[13578])|(1[02]))[\\-]((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-]((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-]((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-]((((0?[13578])|(1[02]))[\\-]((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-]((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-]((0?[1-9])|(1[0-9])|(2[0-8]))))))";
	
	 public static final String rexp2= "\\s*$|((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\\s((([0-1][0-9])|(2?[0-3]))\\:([0-5]?[0-9])((\\s)|(\\:([0-5]?[0-9])))))";


	 public static final String rexp3 = "^\\s*$|([12]\\d{3}[-](([0][1-9])|([1]([012]))))$";



	/**
	 * (验证日期是yyyy-MM-dd支持闰年的正则表达式)
	 * @param str
	 * @return
	 */
	public static boolean isyyyymmdd(String str){
		if(str==null){
			return false;
		}
		boolean matches = str.matches(rexp1);
		return matches;
	}


	/**
	 * (验证日期是yyyy-MM支持闰年的正则表达式)
	 * @param str
	 * @return
	 */
	public static boolean isyyyymm(String str){
		if(str==null){
			return false;
		}
		boolean matches = str.matches(rexp3);
		return matches;
	}
	
	/**
	 * (验证日期是yyyy-MM-dd HH:mm:ss支持闰年的正则表达式)
	 * @param str
	 * @return
	 */
	public static boolean isyyyymmddhhmmss(String str){
		if(str==null){
			return false;
		}
		boolean matches = str.matches(rexp2);
		return matches;
	}
	
	public static void main(String[] args) {
		String dateTime = "2020-03";
		int y = Integer.valueOf(dateTime.substring(0,4));
		int m = Integer.valueOf(dateTime.substring(5,7));
		System.out.println(y+":::"+m);
	}
	
}
